package com.liuhousemyjavabasic.service.serviceImpl;

import com.liuhousemyjavabasic.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private ResourceLoader resourceLoader;
    @Override
    public void deleteFile(String filePath) throws IOException {
        // 获取文件资源
        org.springframework.core.io.Resource resource = resourceLoader.getResource("classpath:" + filePath);
        // 转换为文件系统路径
        Path path = Paths.get(resource.getURI());
        System.out.println(path);
        // 删除文件
        Files.delete(path);
    }
}
